<?PHP
/**
 *          This is the page registered users use to view
 *          all of their upcoming reservations.
 *
 * @version 0.1
 *          Version History:
 *          0.1 Surabhi  created
 *
 * @author  Surabhi Nigam
 */

?>
<?PHP
/* LOGIN SEQUENCE
 * This php code must be included at the top of every page
 *
 */
session_start();
require('../basicInfo/user.php');
require('question.php');
require('course.php');
$_SESSION['currentPage'] = "questionbank";
if(isset($_SESSION['userinfo'])) {
    
    /* user is logged in
     * retreive the user object created when checked
     */
    $userinfo=unserialize($_SESSION['userinfo']);
} else {
    header("Location:../../index.php");
}

?>

<?PHP
$userID=$userinfo->getUid();
$rowsPerPage = 4;
if($_GET['status'] == ""){
   $_GET['status'] = "All"   ;
   $quesArr = QuestionController::getUserQuestions($userID);
}
 else{
    // $_GET['page'] = "";
     if($_GET['status']=='Pending')      {
      $quesArr = QuestionController::getUserPendingQuestions($userID);
     }
     if($_GET['status']=='Approved'){
     $quesArr = QuestionController::getUserApprovedQuestions($userID);
     }
     if($_GET['status']=='Rejected'){
      $quesArr = QuestionController::getUserRejectedQuestions($userID);}

     if( $_GET['status']== "All"){
   $quesArr = QuestionController::getUserQuestions($userID);}
     
   }

$quesArr[sizeof($quesArr)]=null;
$numOfQuesPages = (int) ((sizeof($quesArr)-1) / $rowsPerPage);
if ((sizeof($quesArr)-1) % $rowsPerPage != 0) {
  $numOfQuesPages++;
}

if ($_GET['page'] == "") {
    $_GET['page'] = 1;

}


?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Debugger MMO</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-US" />

<style type="text/css"><!--
  #question_view
    {
        float:left;
        width:496px;
        height:445px;
        border: 3px solid #d5c8a4;
        
        background-color: #FFEBCD;

    }

    #view_heading
    {
        width:496px;
        height:20px;
        margin-top:0px;
        background-color:#DEB887;
        font-family:Verdana;
        text-align:left;
        color: white;
        font-size:15px;
    }

    #view_radios
    {
        margin-top:10px;
        margin-bottom:8px;
        margin-left:20px;
        background-color:#FFEBCD;
        height:30px;
        width: 400px;
        border: none;
    }

    #view_radios select
    {
        width: 100px;
        height:20px;
        border: 1px solid #DEB887;
        float: right;
        margin-right:60px;
    }

    #sort_text
    {
        margin-left:210px;
    }

    #question_view table 
    {
        border:1px solid #DEB887;
        padding: 4px;
        margin-left:10px;
            }

            #question_view table tr
            {
             border:1px solid #DEB887;
            }

            #question_table_thead
            {
                border:none;
                background-color: #FFEBCD;
            }
    #edit_text
    {
        color:gray;
        text-decoration:underline;
    }
    #question_text
    {
        color:blue;
        text-decoration:underline;
    }
    #rejected_text
    {
        color:red;
    }

    #pending_text
    {
        color:#D2691E;
    }

    #page_numbers
    {
       background-color: #FFEBCD;
       float:right;
       border:none;
       margin-right:100px;
       margin-bottom:40px;
       margin-top:30px;
    }

    div#quesTableDiv {
                height: 230px;
                width: 496px;
            }
            table#quesTable {
                margin: auto;
                height: 300px;
                width: 490px;
            }
            table#quesTable th {

                text-align: center;
                font-weight: bold;
                background-color: #FFEBCD;
                color:black;
               
            }

            table#quesTable td {
                padding: 10px 10px 0 10px;
                vertical-align: top;
                font-weight:normal;
            }
            table#quesTable #inst {
                text-align: left;
                width: 496px;
                height: 380px;
            }

            #quesPageLinks
            {
                margin-top:100px;
                
            }
            #quesPageLinks ul
            {
                margin-bottom: 2px;
                padding: 0;
                list-style-type: none;
                text-align: center;
            }
            #quesPageLinks ul li {
                display: inline;
            }
            #quesPageLinks ul li a
            {
                text-decoration: none;
                padding: .2em 1em;
                color: #000000;
            }
            #quesPageLinks ul li a:hover
            {
                color: #c0c0c0;
            }


    li.pageLink {
                cursor: pointer;
            }
            div#quesPageLinks a#selected {
                background-color: #CCCC99;
                /*  border: #886136 1px solid;    */
            }


            

    --></style>

<script type="text/javascript">

function changePage(linkNum) {
                location.replace("viewquestions.php?page="+linkNum+"&status=");
            }

function changeRadio(pageStatus){
            location.replace("viewquestions.php?status="+pageStatus+"&page=");
          }
</script>
</head>
<body>
<?php include "../../layout/header.php"; ?>
<?php include "../../layout/navleft.php"; ?>
<div id="question_view">
    <div id="view_heading">My Questions</div>
    <div id="view_radios">
        <?php $status=($_GET['status']);?>
       <?php if($status=='All'){ ?>
        <input type="radio" name="status" value="All" onclick="changeRadio(this.value)" size="20px" checked="true"/> All 
            <?php }else { ?>
             <input type="radio" name="status" value="All" onclick="changeRadio(this.value)" size="20px" /> All
             <?php }
            ?>

        <?php if($status=='Pending'){ ?>
        <input type="radio" name="status" value="Pending"  size="20px" onclick="changeRadio(this.value)" checked="true"/> Pending <?php } else {?>
        <input type="radio" name="status" value="Pending"  size="20px" onclick="changeRadio(this.value)"/> Pending <?php } ?>

        <?php if($status=='Rejected'){ ?>
        <input type="radio" name="status" value="Rejected" size="20px" onclick="changeRadio(this.value)" checked="true"/> Rejected <?php } else {?>
        <input type="radio" name="status" value="Rejected" size="20px" onclick="changeRadio(this.value)" /> Rejected <?php } ?>

        <?php if($status=='Approved'){ ?>
        <input type="radio" name="status" value="Approved" size="20px" onclick="changeRadio(this.value)" checked="true"/> Approved <?php } else {?>
        <input type="radio" name="status" value="Approved" size="20px" onclick="changeRadio(this.value)" /> Approved <?php } ?>

      
       
        </div>

                             <div id="quesTableDiv">
                                    <table id="quesTable">
    <?PHP
                                        if ($quesArr[0] == null) {
                                            echo "<tr><td colspan='3'>No Questions in this category</td><td></td></tr>";
                                        } else {
                                            //echo "<tr><th>Question Title</th><th>Course</th><th>Topic</th><th >Level</th><th>Date</th><th>Gold</th><th>Status</th><th>Reviews</th> </tr>";
                                            echo "<tr><th width=110px>Question Title</th><th width=110px>Date</th><th width=110px>Status</th><th width=110px>Reviews</th> </tr>";
                                            $page = ($_GET['page'] - 1) * $rowsPerPage;
                                            $endPage = $page + $rowsPerPage;
                                            for ( ; $page < $endPage; $page++) {
                                                if ($quesArr[$page] == null) {
                                                    break;
                                                }
                                                echo "<tr>";
                                                if ($quesArr[$page] != null) {
                                                    $questionID=$quesArr[$page]->getQuestId();
                                                    $questionTID=$quesArr[$page]->getTid();
                                                    $course=QuestionController::getQuestionCourse($questionTID);
                                                    $topic=QuestionController::getQuestionTopic($questionTID);
                                                    

  echo "<td id='question_text'><a".  
	  " href='questionfb.php?qid=".$questionID."&page'>".$quesArr[$page]->getTitle();
          if($quesArr[$page]->getStatus()== "Pending" || $quesArr[$page]->getStatus()=="Rejected")
	  echo " </a> <a href='editquestion.php?quesID=".$questionID ."'> <label id='edit_text'> Edit </label></a></td>";
          else echo " </a> <a href='editquestion.php?quesID=".$questionID ."'>";
                                                     //echo   "<td>". $course."</td>";
                                                       //echo "<td>". $topic." </td>";
                                                       //echo "<td>".$quesArr[$page]->getLevel()."</td>";
                                                        echo "<td>".$quesArr[$page]->getQDate()."</td>";
                                                       // echo "<td>".$quesArr[$page]->getGold()."</td>";
                                                        echo "<td>".$quesArr[$page]->getStatus()."</td>";
                                       
                                        echo "<td><a href='questionfb.php?qid=".$questionID."&page'><label id='question_text'> Reviews </label></a></label> </td>";
                                       
                                                }
                                                echo "</tr>";
                                            }
                                        }?>
                                        </table>
                                              </div>



                             <div id="quesPageLinks">
                                         <ul>
                                         <?PHP
                                        for ($i = 0; $i < $numOfQuesPages; $i++) {
                                            echo "<li class='pageLink' onclick=changePage(".($i+1).")><a";
                                            if ($i == $_GET['page'] - 1) {
                                                echo " id='selected'";
                                            }
                                            echo ">".($i+1)."</a></li>";
                                        }
                                        ?>

                                    </ul>
                                </div>
</div>
<?php include "../../layout/navright.php"; ?>
<?php include "../../layout/footer.php"; ?>

    </body>
    </html>
































